package com.xhb.ui.tools;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

import com.teamdev.jxbrowser.deps.com.google.common.collect.Lists;

public class SortFileUtil {

	public static List<File> sort(String dir) {

		List<File> result = new LinkedList<File>();

		File dirFile = new File(dir);

		List<String> extList = new ArrayList<String>();
		// 文件名排序
		java.util.List<String> array = Lists.newArrayList();
		for (File file : dirFile.listFiles()) {
			extList.add(file.getName().substring(file.getName().lastIndexOf(".")));
			array.add(file.getPath().replace(dirFile.getPath(), "").replace("\\new", "").replace(".png", "")
					.replace(".bmp", "").replace(".BMP", ""));
		}
		Collections.sort(array, new Comparator<String>() {
			public int compare(String o1, String o2) {
				return Integer.parseInt(o1) - Integer.parseInt(o2);
			};
		});

		Integer J = 0;
		for (String f : array) {
			File fName = new File(dirFile.getPath() + "/new" + f + extList.get(J));
			result.add(fName);
			J++;
		}

		return result;
	}
	
	
	public static List<File> sort(String dir,File [] fs) {
		
		List<File> result=new LinkedList<File>();
		
		
		List<String> extList=new ArrayList<String>();
		//文件名排序
		java.util.List<String> array=Lists.newArrayList();
		for (File file : fs) {
			extList.add(file.getName().substring(file.getName().lastIndexOf(".")));
			array.add(file.getPath().replace(dir, "").replace("\\new", "").replace("\\video", "").replace(".png", ""));
		}
		Collections.sort(array, new Comparator<String>() {
			public int compare(String o1, String o2) {
				return Integer.parseInt(o1) - Integer.parseInt(o2);
			};
		});
		
		Integer J=0;
		for (String f : array) {
			File fName=new File(dir+"/new"+f+extList.get(J));
			result.add(fName);
			J++;
		}
		
		return result;
	}
	
	
	public static List<File> sortVideo(String dir,File [] fs) {
		
		List<File> result=new LinkedList<File>();
		
		
		List<String> extList=new ArrayList<String>();
		//文件名排序
		java.util.List<String> array=Lists.newArrayList();
		for (File file : fs) {
			array.add(file.getPath().replace(dir, "").replace("\\new", "").replace("\\video", "").replace(".png", ""));
		}
		Collections.sort(array, new Comparator<String>() {
			public int compare(String o1, String o2) {
				return Integer.parseInt(o1) - Integer.parseInt(o2);
			};
		});
		
		Integer J=0;
		for (String f : array) {
			File fName=new File(dir+"/new"+f+".png");
			result.add(fName);
			J++;
		}
		
		return result;
	}
}
